// react-saga和react-tunk区别
// thunk 是让action 可以成为函数，在action函数里做网络请求
// saga  是让action 不仅可以被reducer监听  也能被sage监听
import { put, takeEvery } from 'redux-saga/effects'
import { actionCreators, actionTypes } from '../components/header/store'
import axios from 'axios'
function* getNameFromHttp() {
  let result = yield axios.get(
    'https://easy-mock.com/mock/5cbd34b469f4db78dc748a05/react/getusername'
  )
  yield put(actionCreators.setname(result.data.username))
}

function* mySaga() {
  yield takeEvery(actionTypes.GET_NAME, getNameFromHttp)
}

export default mySaga
